﻿@model IPagedList<Infinity.BusinessLayer.CategoryViewModel>
@using PagedList;
@using PagedList.Mvc;
<table>
    <tr>
        <th>
            Category ID
        </th>
        <th>
            Category Name
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.CategoryID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Category_Name)
        </td>
        <td>
           
            @Html.ActionLink("Edit", "editeCategory", new { catID = item.CategoryID }, new { @class = "buttonstyle" })
            <button class="DeleteCategory" value="@item.CategoryID"> Delete</button>
        </td>
    </tr>
    <tr>
        <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
    </tr>
}

</table>
<table>
    <tr>
        <td>@Html.PagedListPager(Model, page => Url.Action("Index", new { page, searchBy = Request.QueryString["searchBy"], searchfor = Request.QueryString["searchfor"] }))</td>
    </tr>
</table>

<script src="~/Content/js/jquery-1.11.2.min.js"></script>
<script>
   
    //----- delete category--------------------------------------------
    $(document).ready(function () {
       
        $(".DeleteCategory").click(function (a) {

            var caller = $(this);
            var id = $(this).val();
            var x = $(this).hasClass('fromedite');

            if (confirm("Are you sure you want to delete")) {
                $.ajax({
                    type: "POST",
                    url: "/Managerial/Category/DeleteCategory",
                    data: { catID: id },
                    success: function (list) {
                        
                        if (x == true) {
                            location.href = '/Managerial/Category/Index';
                        }
                        else {
                            $('#CategoryContainer').html(list);
                            alert("deleted Successfully");
                        }
                    },
                    error: function () {
                        alert("can't Delet it");
                    }
                });
            }
        })
    })
    
</script>

